home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
newsgroups
/
misc.20000824-20010305
/
000160_news@columbia.edu _Fri Dec 29 13:42:37 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2020-01-01
|
5KB
Return-Path: <news@columbia.edu>
Received: from watsun.cc.columbia.edu (watsun.cc.columbia.edu [128.59.39.2])
by monire.cc.columbia.edu (8.9.3/8.9.3) with ESMTP id NAA23770
for <kermit.misc@cpunix.cc.columbia.edu>; Fri, 29 Dec 2000 13:42:37 -0500 (EST)
Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id NAA28314
for <kermit.misc@watsun.cc.columbia.edu>; Fri, 29 Dec 2000 13:42:37 -0500 (EST)
Received: (from news@localhost)
by newsmaster.cc.columbia.edu (8.9.3/8.9.3) id NAA08997
for kermit.misc@watsun.cc.columbia.edu; Fri, 29 Dec 2000 13:25:54 -0500 (EST)
X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
From: Igor Sobrado <sobrado@string1.ciencias.uniovi.es>
Subject: Re: Converting struct tm to time_t
Date: 29 Dec 2000 18:24:36 GMT
Organization: Universidad de Oviedo
Message-ID: <92ikt4$q09$1@news01.si.uniovi.es>
To: kermit.misc@columbia.edu
In comp.protocols.kermit.misc Frank da Cruz <fdc@watsun.cc.columbia.edu> wrote:
> How to convert a struct tm (which already is expressed in GMT) to
> a time_t which expresses the clock time in GMT (not local time) in
> a way that is reliable (works in any timezone and takes daylight
> savings into account) and is portable to as many UNIX platforms as
> possible (and how to do the same things on the platforms to which
> this portability does not extend)? The answer (as noted previously)
> is not mktime(), since it presumes its argument is in local time,
> not GMT.
I am not sure about portabilityFrom news@columbia.edu Fri Dec 29 13:42:37 2000
Return-Path: <news@columbia.edu>
Received: from watsun.cc.columbia.edu (watsun.cc.columbia.edu [128.59.39.2])
by fozimane.cc.columbia.edu (8.9.3/8.9.3) with ESMTP id NAA03482
for <kermit.misc@cpunix.cc.columbia.edu>; Fri, 29 Dec 2000 13:42:37 -0500 (EST)
Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id NAA28311
for <kermit.misc@watsun.cc.columbia.edu>; Fri, 29 Dec 2000 13:42:36 -0500 (EST)
Received: (from news@localhost)
by newsmaster.cc.columbia.edu (8.9.3/8.9.3) id NAA08908
for kermit.misc@watsun.cc.columbia.edu; Fri, 29 Dec 2000 13:21:26 -0500 (EST)
X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Converting struct tm to time_t
Date: 29 Dec 2000 10:17:43 -0800
Organization: The Eyrie
Message-ID: <yllmszt7lk.fsf@windlord.stanford.edu>
To: kermit.misc@columbia.edu
In comp.unix.programmer, Frank da Cruz <fdc@watsun.cc.columbia.edu> writes:
> As you say, your code does presume a few things about what time_t is:
> . An integer (in the mathematical sense), unsigned.
> . The number of seconds since 1 Jan 1970 0:00:00.
> If that is always true, fine.
My code doesn't assume it's unsigned; it just won't generate negative
time_t values. It works fine on systems with a signed time_t (basically
all of them).
I believe that both of these assumptions are required by POSIX; they're
certainly true on every UNIX system that I've ever seen. I believe there
are some Windows systems that didn't use an integral time_t, however.
> Anyway, I suppose it's worth a shot. In the meantime, too bad whoever
> thought of mktime() didn't make it do just one thing (in the UNIX
> spirit), instead of two things at once, without allowing those things to
> be done separately.
I believe that mktime is an ANSI/ISO C function. ISO C has no concept in
the language of time zones, only of local time.
> Another solution that had occurred to me was to compare the localtime()
> and gmtime() results for the same clock time, figure out the GMT/UTC
> offset, and deduct it to the target struct tm before passing it to
> mktime(), but gmtime() and localtime() are not among the most portable
> of UNIX APIs,
Really? I've never seen a Unix system without them, and was under the
impression that they were introduced in the early 1980s.
> plus I don't know how consistent their semantics are across platforms,
> e.g. if you give them a seconds or minutes field greater than 60 or less
> than 0, etc.
Neither gmtime() nor localtime() take something that has a seconds or
minutes field, so I assume that you're talking about mktime(). mktime()'s
normalization of out-of-range values is a requirement of its definition,
which I believe is in ANSI C.
--
Russ Allbery (rra@stanford.edu) <http://www.eyrie.org/~eagle/>
| mktime(3C)
V
+-------- time_t (UTC+offset)
| |
| | gmtime(3C)
| V
time_offset <---+ struct tm (UTC+offset)
| | |
V | | mktime(3C)
(used to change | V
MDTM time (UTC) to +---- time_t (UTC+offset+offset)
local time before
convert it to time_t)
Hope this helps (and hope this works!),
Igor.
--
Igor Sobrado, UK34436 - sobrado@acm.org